public class Leetcode1823 {
    public int findTheWinner(int n, int k) {
        return findTheWinnerIndex(n, k) + 1;
    }

    public int findTheWinnerIndex(int n, int k) {
        if (n == 1) {
            return 0;
        }

        return (findTheWinnerIndex(n - 1, k) + k) % n;
    }
}

